#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=200000, maxa=1000000;
int spacecnt=0;

class ChairmanTree {
public:
  int v;
  ChairmanTree *left, *right;

  ChairmanTree() {
    v=0;
    left=right=NULL;
    spacecnt++;
  }

  void add(ChairmanTree *o, int t, int tv, int l, int r) {
    if (l==r) {
      if (o) {
	v = o->v+tv;
      } else {
	v = tv;
      }
    } else {
      int mid=(l+r)/2;
      if (t<=mid) {
	left = new ChairmanTree();
	if (o) {
	  right = o->right;
	  left->add(o->left, t, tv, l, mid);
	} else {
	  left->add(NULL, t, tv, l, mid);
	}
      } else {
	right = new ChairmanTree();
	if (o) {
	  left = o->left;
	  right->add(o->right, t, tv, mid+1, r);
	} else {
	  right->add(NULL, t, tv, mid+1, r);
	}
      }
      v=0;
      if (left) {
	v += left->v;
      }
      if (right) {
	v += right->v;
      }
    }
  }
};

int getKth(int k, int n, int tl, int tr, ChairmanTree *l[], ChairmanTree *r[]) {
  if (tl==tr) {
    return tl;
  }
  int sum=0, mid=(tl+tr)/2;
  for (int i=1; i<=n; i++) {
    if (l[i] && l[i]->left) {
      sum -= l[i]->left->v;
    }
    if (r[i] && r[i]->left) {
      sum += r[i]->left->v;
    }
  }
  if (k<=sum) {
    for (int i=1; i<=n; i++) {
      if (l[i]) {
	l[i] = l[i]->left;
      }
      if (r[i]) {
	r[i] = r[i]->left;
      }
    }
    return getKth(k, n, tl, mid, l, r);
  } else {
    for (int i=1; i<=n; i++) {
      if (l[i]) {
	l[i] = l[i]->right;
      }
      if (r[i]) {
	r[i] = r[i]->right;
      }    }
    return getKth(k-sum, n, mid+1, tr, l, r);
  }
}

int main() {
#ifdef DEBUG
  freopen("3379.in", "r", stdin);
  freopen("3379.out", "w", stdout);
#endif

  static ChairmanTree *sgt[maxn+1];
  static int a[maxn+1];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
    sgt[i] = new ChairmanTree();
    sgt[i]->add(sgt[i-1], a[i], 1, 1, maxa);
  }

  static ChairmanTree *l[6], *r[6];
  for (int i=1; i<=m; i++) {
    int k, p;
    scanf("%d %d", &k, &p);
    for (int i=1; i<=k; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      l[i] = sgt[x-1], r[i]=sgt[y];
    }
    printf("%d\n", getKth(p, k, 1, maxa, l, r));
  }

#ifdef DEBUG
  printf("Space:%d\n", spacecnt);
#endif

  fclose(stdin);
  fclose(stdout);
  return 0;
}
